<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>角色</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<blockquote class="layui-elem-quote list_search">
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal roleAdd_btn layui-btn-disabled" shiro:lacksPermission="sys:role:save"><i
                    class="layui-icon">&#xe608;</i> 添加角色</a>
            <a class="layui-btn layui-btn-normal roleAdd_btn" shiro:hasPermission="sys:role:save"><i
                    class="layui-icon">&#xe608;</i> 添加角色</a>
        </div>
</blockquote>
<table id="roleList" class="roleList" lay-filter="roleList"></table>
<script type="text/html" id="barEdit">
        <a class="layui-btn layui-btn-xs layui-btn-disabled" shiro:lacksPermission="sys:role:update">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit" shiro:hasPermission="sys:role:update">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"  shiro:lacksPermission="sys:role:delete">删除</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" shiro:hasPermission="sys:role:delete">删除</a>
</script>
<script th:src="@{/src/layui.js}"></script>

<script>

    layui.use(['table','jquery','layer'],function () {
        var table = layui.table,
            $= layui.jquery;
        table.render({
            elem:'#roleList',
            url:'/roles/list',
            limit:5,
            limits:[5,10,15],
            page:true,
            cols:[
                [
                    {field:'roleId',title:'ID',width:80},
                    {field:'roleName',title:'角色名称',align:'center'},
                    {field:'roleRemark',title:"角色描述"},
                    {field:'operate',title:'操作',templet:'#barEdit'}
                ]
            ],
            parseData:function (res) {
                return {
                    "code":res.code==200?0:res.code,
                    "msg":res.message,
                    "count":res.data.total,
                    "data":res.data.list
                }
            }
        })


        $(".roleAdd_btn").click(function () {
            var index = layer.open({
                type:2,
                title:'添加角色',
                content:'/sys/addRole'
            })
            $(window).resize(function () {
                layer.full(index);
            })
            layer.full(index);
        })
        
        
        //编辑
        table.on('tool(roleList)',function (row) {
            var event = row.event;
            var data = row.data; //获取当前行数据
            if(event == 'edit'){
                layer.open({
                    type:2,
                    title:'编辑角色',
                    area:["500px","500px"],
                    content:'/roles/editRole/'+data.roleId
                })
            }else if(event == 'del'){
                layer.confirm('确认删除？',function (index) {
                    $.ajax({
                        url:'/roles/delete/'+data.roleId,
                        type:'delete',
                        dataType:'json',
                        success:function (res) {
                            if(res.code == 200){
                                layer.msg('删除成功',{icon:1},function () {
                                    location.reload();
                                })
                            }else{
                                layer.msg('删除失败',{icon:5})
                            }
                        }
                    })

                    /*layer.close(roleList);*/
                })
            }
        })
        
    })

</script>




</body>
</html>